<template>
    <div class="view">
        <div class="page-signup" v-if="!loadShow">
            <div class="m-header">
                <div class="logo">
                    <img src="~@/assets/img/logo.png" alt="">
                </div>
                <div class="session">第{{actInfo.futureChineseNum}}届</div>
                <div class="timeCut">
                    【还有 <span class="day">{{countDown}}</span> 天】
                </div>
            </div>
            <component :is="userType" :actInfo="actInfo"></component>
        </div>
        <div class="loading" v-if="loadShow">
            <div class="loading-con">
                <img src="@/assets/img/loading.gif" alt="">
                <p>下一阶段还未开始...</p>
            </div>
        </div>
    </div>
</template>

<script>
import mTeacher from './unitSub/teach'
import mStudent from './unitSub/stu'
import {timeFamter} from '@/utils/common'
import * as api from '@/api/index';
export default {
    name: 'singup',
    components: { 
        mTeacher,
        mStudent
    },
    data () {
        return {
            userInfo: JSON.parse(localStorage.getItem("userInfo")),
            userType: '',
            actInfo:{},
            countDown:'',
            loadShow: true
        }
    },
    computed: {
        
    },
    mounted(){
        this.getInit()
    },
    methods: {
        /*****
		 * 获取活动信息
		 * sstUserType: 1管理 2教师 3学生
         * getFutureInfoById:按照期编号查询诗王争霸期信息 ->活动第几届
         * getInfoById:按照阶段号查询阶段信息 ->报名开始时间到结束时间
		 * ****/ 
        async getInit(){
            this.userType = this.userInfo.sstUserType == 2?'mTeacher':'mStudent'
            var data = {
                futureId: this.userInfo.futureId,
				stagesId: this.userInfo.stagesId,	
            }
            var [res1,res2] = await Promise.all([
                                    api.getFutureInfoById(data),
                                    api.getInfoById(data)])
            if(res1.resultCode){
                this.actInfo = res1.value
            }  
            if(res2.resultCode){
                this.actInfo = {...this.actInfo,...res2.value}
                const {stagesStartTime,stagesEndTime} = this.actInfo
                var startDate = timeFamter(), endDate = timeFamter(stagesEndTime) 
                var days=(endDate - startDate)/(1*24*60*60*1000);
                if(days<0){
                    this.loadShow = true
                    return false
                }
                this.loadShow = false
                this.countDown = days&&days>0? parseInt(days): 0

            }           

        },
    }
}
</script>
